﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{       
    public class ABINFONReport : BaseReport
    {
        string strCompany = "HLT";
        string strExcelFile = "";
        string sheetName = "";
        string Standard = "ABINFON";
        string filePath = @"C:\intex.w\Report\HLT\HLTPlanningReport.xls";
        public ABINFONReport()
            : base()
        {
        }
        public ABINFONReport(Dictionary<string, object> dicParamater)
            : base(dicParamater)
        { 
            strCompany = dicParamater["Company"].ToString().Trim();
            strExcelFile = dicParamater["ExcelFile"].ToString().Trim();
            strExcelFile = @"HLT\HLTPlanningReport.xls";
            #region Excel  columns
            columns.Add("VKPWUTERM");
            columns.Add("REMAINDAYS");
            columns.Add("KDKUNDNA");
            columns.Add("VKPLIEFTERM");
            columns.Add("STATUS");
            columns.Add("JSPLANDATE");
            columns.Add("JSACTDATE");
            columns.Add("VWPENDDATE");
            columns.Add("VWAENDDATE");
            columns.Add("YDPENDDATE");
            columns.Add("YDAENDDATE");
            columns.Add("WFPENDDATE");
            columns.Add("WFAENDDATE");
            columns.Add("GRPENDDATE");
            columns.Add("GRAENDDATE");
            columns.Add("FNPENDDATE");
            columns.Add("FNAENDDATE");
            columns.Add("VKPAUFNUM");
            columns.Add("VKPPOSTYP");
            columns.Add("VKPNEUDAT");
            columns.Add("ARTICLE");
            columns.Add("VKPMENGE1");
            columns.Add("VKPRESERV");
            columns.Add("ABARESQTY");            
            columns.Add("VKPZUGET"); 
            columns.Add("VKPMEEH");
            columns.Add("ABPBESCHICH");
            columns.Add("FNVKDIFF");
            columns.Add("SALESREPLAY");
            columns.Add("STDBATCHNO");
            columns.Add("VWFARBE");
            columns.Add("WEFTYARNSTATUS");
            columns.Add("VWORDERNUM");
            columns.Add("GWBORDER");
            columns.Add("FORDERNUM");
            columns.Add("PLANFNVWDIFF");
            columns.Add("VWPSTARTDATE");
            columns.Add("WPRODUCER");
            columns.Add("SPRODUCER");
            columns.Add("SBEAMLENG");
            columns.Add("SBEAMNO");
            columns.Add("SBEAMDATE");
            columns.Add("BMBEM");
            columns.Add("BEAMALENG");
            columns.Add("VWDIFFAP");
            columns.Add("GREIGEPLANLENGTH");
            columns.Add("ACTWEAVEIN");
            columns.Add("GRALENG");
            columns.Add("FPLANLENG");
            columns.Add("FACTLENG");
            columns.Add("FNGRSHRINK");
            #endregion
        }
        public void FillInExcelData(ArrayList columns, DataTable dtSoruce, int xStart = 3, int yStart = 1)
        { 
            try
            {
                exAgent.DataTableToExcel(dtSoruce, 3, 1); 
                return;
                int x = xStart;
                int yend=dtSoruce.Columns.Count+1;
                int maxrowid = 0;
                string rowid;
                string column;
                string progress;
                int MaxRows = dtSoruce.Rows.Count;
                 foreach (DataRow dwTemp in dtSoruce.Rows)
                {
                    progress = "写入记录" + x.ToString() + "/" + MaxRows.ToString();
                    EventDispatcher.Instance.RaiseStatus(progress, StatusEventType.StartProgress);
                    yStart = 1;
                    rowid = dwTemp["ROWID"].ToString();
                    if (rowid == "")
                    {
                        dwTemp["ROWID"] = (maxrowid + 1).ToString();
                        maxrowid++;
                    }
                    else
                    {
                        maxrowid = System.Convert.ToInt16(rowid);
                    }
                    for (int y = yStart; y < yend; y++)
                    {
                        column = exAgent.GetCellValue(2, y).ToString().Trim();
                        if (dtSoruce.Columns.Contains(column))
                        {
                            exAgent.SetCellValue(x, y, dwTemp[column]);
                        }
                    } 
                    x++;
                 }
                 progress = "写入完成" +MaxRows.ToString();
                 EventDispatcher.Instance.RaiseStatus(progress, StatusEventType.StopProgress);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public override void WriteExcelReport(string fileType)
        { 
            exAgent.Company = strCompany;
            exAgent.strExcelFile = strExcelFile;
            string filedate = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
            filePath = @"C:\intex.w\Report\Planning\ABINFON.xls";
            exAgent.Open(filePath);
            exAgent.SetCurrentSheet("生产订单跟踪");
            FillInExcelData(columns, dsSource.Tables["ABPOS"]);
            base.WriteExcelReport(fileType);          
        }
    }
}
